"""
编辑客户关怀
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
from selenium.webdriver.support.select import Select
#定位器
name_locator = (By.NAME, "name")
password_locator = (By.NAME, "password")
login_locator = (By.CSS_SELECTOR, "body > div.container > div > div.span4 > div > form > fieldset > input.btn.btn-primary")
kh_link_locator =(By.LINK_TEXT,"客户")
kh_khgh_locator = (By.LINK_TEXT,"客户关怀")
kh_khgh_bj_locator = (By.LINK_TEXT,"编辑")
kh_khgh_xgkhgh_kh_locator = (By.ID,"customer_name")
kh_khgh_xgkhgh_lxr_locator = (By.ID,"contacts_name")
kh_khgh_xgkhgh_ghzt_locator = (By.ID,"name")
kh_khgh_xgkhgh_ghrq_locator = (By.ID,"contacts_name")
kh_khgh_xgkhgh_zxr_locator = (By.ID,"owner_name")
kh_khgh_xgkhgh_ghlx_locator = (By.ID,"type")
kh_khgh_xgkhgh_ghlr_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > textarea")
kh_khgh_xgkhgh_bz_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tbody > tr:nth-child(6) > td:nth-child(2) > textarea")
kh_khgh_xgkhgh_bc_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > thead > tr > td:nth-child(2) > input.btn.btn-primary")
#数据
name = "admin"
password = "123456"
kh = "C4"
lxr = "胡雨龙"
ghzt = "生日快乐"
ghrq = "2023-04-27 17:20"
zxr = "admin"
ghlr = "生日快乐"
bz = "88888"

#操作
#打开浏览器
driver = webdriver.Chrome()
#最大化窗口
driver.maximize_window()
#进入悟空CRM登录界面
driver.get("http://192.168.1.25/crm/")
#输入用户名
driver.find_element(*name_locator).send_keys(name)
#输入密码
driver.find_element(*password_locator).send_keys(password)
#点击确定按钮
driver.find_element(*login_locator).click()
#点击线索按钮
driver.find_element(*kh_link_locator).click()
#点击客户关怀
driver.find_element(*kh_khgh_locator).click()
#点击编辑
driver.find_element(*kh_khgh_bj_locator).click()
#输入客户
driver.find_element(*kh_khgh_xgkhgh_kh_locator).clear()
driver.find_element(*kh_khgh_xgkhgh_kh_locator).send_keys(kh)
#输入联系人
driver.find_element(*kh_khgh_xgkhgh_lxr_locator).clear()
driver.find_element(*kh_khgh_xgkhgh_lxr_locator).send_keys(lxr)
#输入关怀主题
driver.find_element(*kh_khgh_xgkhgh_ghzt_locator).clear()
driver.find_element(*kh_khgh_xgkhgh_ghzt_locator).send_keys(ghzt)
#输入关怀日期
driver.find_element(*kh_khgh_xgkhgh_ghrq_locator).clear()
driver.find_element(*kh_khgh_xgkhgh_ghrq_locator).send_keys(ghrq)
#输入执行人
driver.find_element(*kh_khgh_xgkhgh_zxr_locator).clear()
driver.find_element(*kh_khgh_xgkhgh_zxr_locator).send_keys(zxr)
#选择关怀类型
GHLX = driver.find_element(*kh_khgh_xgkhgh_ghlx_locator)
Select(GHLX).select_by_index(1)
#输入关怀内容
driver.find_element(*kh_khgh_xgkhgh_ghlr_locator).clear()
driver.find_element(*kh_khgh_xgkhgh_ghlr_locator).send_keys(ghlr)
#输入备注
driver.find_element(*kh_khgh_xgkhgh_bz_locator).clear()
driver.find_element(*kh_khgh_xgkhgh_bz_locator).send_keys(bz)
#点击保存
driver.find_element(*kh_khgh_xgkhgh_bc_locator).click()
sleep(5)

if __name__ == '__main__':
    unittest.main()